package learningThread.syn.synchronizedMethodLockObj.testvolatile;

/**
 * volatile 主要是当前线程访问时 强制从公共堆栈中取值
 * 关键字volatile都是线程同步的轻量级实现，volatile性能比syn好。
 * volatile只能修饰变量，syn修饰方法,方法块
 * volatile不会阻塞，syn会阻塞
 * volatile保证可见性但不保证原子性, syn可保证原子性，也可间接保证可见性
 */
public class RunThread extends Thread{

     private volatile boolean isRunning = false;

    public boolean isRunning() {
        return isRunning;
    }

    public void setRunning(boolean running) {
        isRunning = running;
    }

    @Override
    public void run() {
        System.out.println("进入了run...");
        if (isRunning == true) {

        }
        System.out.println("线程停止了...");
    }
}
